package io.geekidea.boot.test.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.dto.PayOrderDto;
import io.geekidea.boot.test.query.PayOrderQuery;
import io.geekidea.boot.test.service.PayOrderService;
import io.geekidea.boot.test.vo.PayOrderVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 订单 控制器
 *
 * @author geekidea
 * @since 2025-03-26
 */
@Slf4j
@RestController
@Tag(name = "订单")
@RequestMapping("/admin/payOrder")
public class PayOrderController {

    @Autowired
    private PayOrderService payOrderService;

    /**
     * 添加订单
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加订单")
    @PostMapping("/addPayOrder")
    @Permission("pay:order:add")
    public ApiResult addPayOrder(@Valid @RequestBody PayOrderDto dto) {
        log.info("添加订单：{}", dto);
        boolean flag = payOrderService.addPayOrder(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改订单
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改订单")
    @PostMapping("/updatePayOrder")
    @Permission("pay:order:update")
    public ApiResult updatePayOrder(@Valid @RequestBody PayOrderDto dto) {
        log.info("修改订单：{}", dto);
        boolean flag = payOrderService.updatePayOrder(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除订单
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除订单")
    @PostMapping("/deletePayOrder/{id}")
    @Permission("pay:order:delete")
    public ApiResult deletePayOrder(@PathVariable Long id) {
        log.info("删除订单：{}", id);
        boolean flag = payOrderService.deletePayOrder(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取订单详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取订单详情")
    @PostMapping("/getPayOrder/{id}")
    @Permission("pay:order:info")
    public ApiResult<PayOrderVo> getPayOrder(@PathVariable Long id) {
        log.info("获取订单详情：{}", id);
        PayOrderVo payOrderVo = payOrderService.getPayOrderById(id);
        return ApiResult.success(payOrderVo);
    }

    /**
     * 获取订单分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取订单分页列表")
    @PostMapping("/getPayOrderPage")
    @Permission("pay:order:page")
    public ApiResult<PayOrderVo> getPayOrderPage(@Valid @RequestBody PayOrderQuery query) {
        log.info("获取订单分页列表：{}", query);
        Paging<PayOrderVo> paging = payOrderService.getPayOrderPage(query);
        return ApiResult.success(paging);
    }

}
